from common.BasePages import BasePage


class AnnouncementPage(BasePage):

    def announcement_url(self):
        self.goto_url("systemManagement/layout/notice")

    def create_announcement(self):
        # 新增公告
        self.page.get_by_role("button", name="新增").click()
        self.page.get_by_role("dialog", name="公告信息新增").get_by_placeholder("请输入公告标题").click()
        self.page.get_by_role("dialog", name="公告信息新增").get_by_placeholder("请输入公告标题").fill("测试公告")
        self.page.get_by_role("textbox", name="选择日期").click()
        self.page.get_by_role("button", name="一周").click()
        self.page.get_by_role("button", name="").click()
        self.page.get_by_role("row", name="姓名 账户 联系邮箱 组织").locator("span").nth(1).click()
        self.page.get_by_role("button", name="确定").click()
        self.page.locator("textarea").click()
        self.page.locator("textarea").fill("公告内容是什么")
        self.page.get_by_role("button", name="确 定").click()
        self.page.get_by_text("保存成功").click()

    def edit_announcement(self):
        # 编辑公告
        self.page.get_by_role("cell", name="  ").locator("i").nth(1).click()
        self.page.locator("textarea").click()
        self.page.locator("textarea").fill("公告内容是什么2")
        self.page.get_by_role("button", name="确 定").click()

    def delete_announcement(self):
        # 删除成功
        self.page.get_by_role("cell", name="  ").locator("i").nth(2).click()
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("删除成功!")
